package net.tv90.bfmccore.util;

import net.tv90.bfmccore.SlainListener;
import net.tv90.bfmccore.event.RibbonGetEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class Ribbon {
    /**
     * 记录玩家的操作次数，该操作达到指定次数可获得相应勋带
     *
     * @param player     玩家
     * @param ribbonType 勋带英文名
     * @param ribbonName 勋带中文名
     * @param num        触发多少次数可获得一枚勋带
     */
    public static void addNumberForRibbon(Player player, String ribbonType, String ribbonName, int num) {
        SlainListener.RibbonCacheMap.putIfAbsent(player.getName() + "_" + ribbonType, 0);
        SlainListener.RibbonNumMap.putIfAbsent(player.getName() + "_" + ribbonType + "_Ribbon", 0);
        int value = SlainListener.RibbonCacheMap.get(player.getName() + "_" + ribbonType);
        value++;
        SlainListener.RibbonCacheMap.put(player.getName() + "_" + ribbonType, value);
        if (value == num) {
            int RibbonNum = SlainListener.RibbonNumMap.get(player.getName() + "_" + ribbonType + "_Ribbon");
            RibbonNum++;
            SlainListener.RibbonNumMap.put(player.getName() + "_" + ribbonType + "_Ribbon", RibbonNum);
            Bukkit.getServer().getPluginManager().callEvent(new RibbonGetEvent(player, null, ribbonName, "Ribbon_" + ribbonType, RibbonNum));
            SlainListener.RibbonCacheMap.put(player.getName() + "_" + ribbonType, 0);
        }
    }
}
